﻿<?php
Class User extends CI_Model
{

    function __construct(){
	   parent::__construct();
    }

		######  Attribute  ###### 
    var $id ; ######  รหัส  ######
    var $username ; ######  ชื่อผู้ใช้  ######
    var $password ; ######  รหัสผ่าน  ######
    var $name ; ######  ชื่อ  ######
    var $lastname ; ######  นามสกุล  ######
    var $status ; ######  สถานะ  ######
		###### End Attribute  ###### 

###### SET : $id ######
    function setId($id){
        $this->id = $id; 
     }
###### End SET : $id ###### 


###### GET : $id ######
    function getId(){
        return $this->id; 
     }
###### End GET : $id ###### 


###### SET : $username ######
    function setUsername($username){
        $this->username = $username; 
     }
###### End SET : $username ###### 


###### GET : $username ######
    function getUsername(){
        return $this->username; 
     }
###### End GET : $username ###### 


###### SET : $password ######
    function setPassword($password){
        $this->password = $password; 
     }
###### End SET : $password ###### 


###### GET : $password ######
    function getPassword(){
        return $this->password; 
     }
###### End GET : $password ###### 


###### SET : $name ######
    function setName($name){
        $this->name = $name; 
     }
###### End SET : $name ###### 


###### GET : $name ######
    function getName(){
        return $this->name; 
     }
###### End GET : $name ###### 


###### SET : $lastname ######
    function setLastname($lastname){
        $this->lastname = $lastname; 
     }
###### End SET : $lastname ###### 


###### GET : $lastname ######
    function getLastname(){
        return $this->lastname; 
     }
###### End GET : $lastname ###### 


 ###### SET : $status ######
    function setStatus($status){
        $this->status = $status; 
     }
###### End SET : $status ###### 


###### GET : $status ######
    function getStatus(){
        return $this->status; 
     }
###### End GET : $status ###### 


 function login($username, $password)
 {
   $this -> db -> select('*');
   $this -> db -> from('user');
   $this -> db -> where('username', $username);
   $this -> db -> where('password', MD5($password));
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
 function getIdUser()
		{
			$this->db->where('id',$this->getId());
			$query = $this->db->get('user')->result_array();
			return $query;
	
		}
		
function getUser()
		{
			$query = $this->db->get('user')->result_array();
			return $query;
	
		}

 function addUser()
		{

			$data = array(					
							'username' => $this->getUsername(),
							'password' => md5($this->getPassword()),
							'name' => $this->getName(),
							'lastname' => $this->getLastname(),
							'status' => $this->getStatus()
						);
			$this->db->insert('user', $data);			
		}


function updateUser()
		{

			$data = array(					
							'name' => $this->getName(),
							'lastname' => $this->getLastname()
						);

			$this->db->where('id', $this->getId());
			$this->db->update('user', $data);		
		}
		
function deleteUser()
		{
			
			$this->db->where('id', $this->getId());
			$this->db->delete('user');		
			
		}

}
?>

